import React, { useEffect, useState } from 'react'
import axios from 'axios';
import { useRequest } from 'ahooks';
import { message } from 'antd';
import NewsPublishTable from '@/components/NewsPublishTable';
import usePublish from '@/util/usePublish';

//#region 不封装，不使用自定义hooks的方案
// 发起网络请求，发布管理-已发布页面，要显示当前用户+发布状态（publishState===2）为 已发布 所有新闻信息,
// const getPublishedRequest = (userName: string) => {
//     return axios.get(`http://localhost:3000/news?_expand=category&author=${userName}&publishState=2`);
// };
//#endregion
export default function Published() {
    //从localStorage获取当前用户信息
    const currentUser = JSON.parse(localStorage.getItem('token') as string);
    //#region 不封装，不使用自定义hooks的方案
    // 表格数据源保存
    // const [dataSource, setDataSource] = useState<any>([]);
    // useRequest - 获取当前用户 已发布 新闻（publishState===2）信息
    // const { run: getPublishedData, loading: getPublishedLoading } = useRequest(getPublishedRequest, {
    //     throttleWait: 300,
    //     manual: true,
    //     onSuccess: (result: any, params) => {
    //         if (result.status === 200) {
    //             console.log(result.data);
    //             setDataSource(result.data);
    //         }
    //     },
    //     onError(e, params) {
    //         message.warning('请求已发布的新闻数据失败');
    //     },
    // });
    // useEffect(() => {
    //     getPublishedData(currentUser[0].username);
    // }, [currentUser[0].username])
    //#endregion
    const { dataSource } = usePublish(2);
    return (
        <div>
            <NewsPublishTable dataSource={dataSource} ></NewsPublishTable>
        </div>
    )
}
